package com.hk.commons.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.hk.commons.entity.product.ProductInfo;
import org.hibernate.annotations.GenericGenerator;

import java.sql.Timestamp;

@Entity
@Table(name = "t_activity_info")
public class Activity implements java.io.Serializable ,  Comparable<Activity>{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7149469707724123592L;
	
	@Id
    @GeneratedValue (generator =  "paymentableGenerator" )    
    @GenericGenerator (name =  "paymentableGenerator" , strategy =  "increment" ) 
	private Integer id;
	
	private String name;
	
	private String type;
	
	private String picAddress; 
	
	private String url; 
	
	private Integer status;

	private String actDesc;

	private String channel;

	/**
	 * 发布位置：1-首页Bananer, 2-活动中心
	 */
	private String location;

	//是否分享
	private Integer isShare;

	/**
	 * 是否已结束
	 */
	private Integer startStatus;


	/**
	 * 活动开始时间
	 * */
	private Timestamp startTime;

	/**
	 * 活动结束时间
	 * */
	private Timestamp endTime;
	
	private Long cts;
	
	private Long creator;


	public Integer getIsShare() {
		return isShare;
	}

	public void setIsShare(Integer isShare) {
		this.isShare = isShare;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Long getCts() {
		return cts;
	}

	public void setCts(Long cts) {
		this.cts = cts;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Long getCreator() {
		return creator;
	}

	public void setCreator(Long creator) {
		this.creator = creator;
	}

	public String getPicAddress() {
		return picAddress;
	}

	public void setPicAddress(String picAddress) {
		this.picAddress = picAddress;
	}

	public String getActDesc() {
		return actDesc;
	}

	public void setActDesc(String actDesc) {
		this.actDesc = actDesc;
	}

	public String getChannel() {
		return channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public Integer getStartStatus() {
		return startStatus;
	}

	public void setStartStatus(Integer startStatus) {
		this.startStatus = startStatus;
	}

	public Timestamp getStartTime() {
		return startTime;
	}

	public void setStartTime(Timestamp startTime) {
		this.startTime = startTime;
	}

	public Timestamp getEndTime() {
		return endTime;
	}

	public void setEndTime(Timestamp endTime) {
		this.endTime = endTime;
	}


	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	@Override
	public int compareTo(Activity o) {
		if (this == null || o == null) {
			return 0;
		}

		//01 对比状态
		int compareResult = compareStatus(this, o);
		if (compareResult != 0) {
			return compareResult;
		}

		//02 对比时间
		compareResult = compareTime(this, o);
		if (compareResult != 0) {
			return compareResult;
		}

		return compareResult;
	}

	public int compareStatus(Activity x, Activity y){
		int compareResult = 0;
		if(x.getStartStatus() == y.getStartStatus()){
			compareResult =  0;
		}else if (x.getStartStatus() == 3){
			compareResult =  1;
		}else if (x.getStartStatus() == 2){
			compareResult =  -1;
		}else if (x.getStartStatus() == 1){
			//预热中
			if(y.getStartStatus() == 3){
				compareResult = -1;
			}else{
				compareResult = 1;
			}
		}

		//System.out.println("compareStatus : " + " x.name = " + x.getName() +  " x.startStatus = " + x.getStartStatus() +  " y.name = " + y.getName() +  "   y.startStatus = = " +  y.getStartStatus() + " compareResult = " + compareResult );

		return compareResult;
	}


	public int compareTime(Activity x, Activity y){
		return x.getStartTime().compareTo(y.getStartTime()) * -1;
	}
}


 
